package com.springboot.code.String;

import org.apache.commons.fileupload.FileItem;
import org.apache.commons.fileupload.disk.DiskFileItemFactory;
import org.apache.tomcat.util.http.fileupload.*;
import org.springframework.http.MediaType;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.multipart.commons.CommonsMultipartFile;

import java.io.File;
import java.io.InputStream;
import java.io.OutputStream;
import java.nio.file.Files;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;

/**
 * DESC:
 *
 * @author WangJie
 * @date Created in 2023-07-03 20:44
 */
public class Test {

    public static void main(String[] args) {
        /*File file = new File("G:\\Download\\new 1.csv");
        MultipartFile multipartFile = getMultipartFile(file);
        List<DataFile> list = CsvUtils.getCsvDataMethod(multipartFile, DataFile.class);
        System.out.println(list);*/
        methodName();

    }

    public static void methodName(){
        List<String> list = new ArrayList<>();
        list.add("1");
        list.add("2");
        list.add("3");
        System.out.println(Collections.min(list));
    }

    public static MultipartFile getMultipartFile(File file) {
        FileItem fileItem = new DiskFileItemFactory().createItem("file", MediaType.TEXT_PLAIN_VALUE,true, file.getName());
        try (InputStream input = Files.newInputStream(file.toPath());
             OutputStream os = fileItem.getOutputStream()) {
            IOUtils.copy(input, os);
        } catch (Exception e) {
            throw new IllegalArgumentException("Invalid file: " + e, e);
        }
        return new CommonsMultipartFile(fileItem);
    }
}
